package com.googlecode.uipipedream.impl;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import com.googlecode.uipipedream.spec.ColourModel;

/**
 * Contains the user selected colours.
 * @author <a href="http://daemonsadvocate.blogspot.com/">Matthew B. Gray</a>
 */
public class ColourSwatch extends Canvas {
	private static final long serialVersionUID = -8523194579277895075L;
	private ColourModel model;
	private Color color;
	
	@Override public Dimension preferredSize() { return new Dimension(20, 20); }
	@Override public Dimension minimumSize() { return new Dimension(5, 5); }
	
	public ColourSwatch(ColourModel model, Color color) {
		this.model = model;
		this.color = color;
		setBackground(Color.black);
	}
	
	public Color getColor() { return color; }
	public ColourModel getColourModel() { return this.model; }
	
	public void setColor(Color c) {
		color = c;
		repaint();
	}
	
	@Override public void paint(Graphics g) {
		g.setColor(color);
		g.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
		g.setColor(Color.white);
		g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
	}
	
	@Override public void update(Graphics g) { super.update(g); }
}